package com.haiyou.monitor;


import org.springframework.boot.SpringApplication;

import org.springframework.boot.autoconfigure.SpringBootApplication;

import org.springframework.context.annotation.ComponentScan;

import org.springframework.scheduling.annotation.EnableScheduling;

import com.haiyou.common.constants.ServerConfigConstants;
import com.haiyou.common.constants.ServerTypeConstants;
import com.haiyou.common.system.Properties;
import com.haiyou.common.system.SystemProperties;
import com.haiyou.common.util.string.StringFormatUitls;
import lombok.extern.slf4j.Slf4j;
import de.codecentric.boot.admin.server.config.EnableAdminServer;


/**
 * @Description:springboot admin 监控启动类
 * @author xingyuan
 * @date 2022年8月19日 下午3:41:57
 */
@Slf4j
@EnableAdminServer
@EnableScheduling
@SpringBootApplication
@ComponentScan(value= {"com.haiyou.monitor","com.haiyou.common"})
public class MonitorApplication {

	/**
	 * 设置节点类型
	 */
	public static String nodeType = ServerTypeConstants.server_monitor;
	
	public static void main(String[] args) {
		
		try {
			//加载配置信息
			SystemProperties.load(SystemProperties.getResourcesAbsolutePath(ServerConfigConstants.spring_path,
					ServerConfigConstants.config_properties));
			
			//设置参数
			setProperty();
			
			//启动
			SpringApplication.run(MonitorApplication.class,args);

			log.info("=============={},启动成功==========",Properties.spring_application_name());
			
		} catch (Exception e) {
			log.info("启动服务器发生异常,启动服务器失败");
			log.error(e.getMessage(), e);
			System.exit(0);
		}
	}
	
	/**
	 * 设置一些类型
	 */
	public static void setProperty() {
		
    	System.setProperty("spring.devtools.restart.enabled", "false");
		
		//设置节点类型
		System.setProperty(ServerConfigConstants.server_node_type,
				nodeType);
		
		String nameFormat = "{}({})";
		
		String name = StringFormatUitls.format(nameFormat, nodeType,Properties.server_node_id());
		
		//设置应用名称
		System.setProperty(ServerConfigConstants.spring_application_name,name);
	}

	
}
